﻿using System;
using System.Collections.Generic;
using System.Text;

using MyLibrary.ThreeLayer.DataAccess.Enum;
using MyLibrary.ThreeLayer.DataAccess.Interface;
using MyLibrary.ThreeLayer.DataAccess.Provider.SQLParser.MSSQL;
using MyLibrary.ThreeLayer.DataAccess.Provider.SQLParser.MySQL;


namespace MyLibrary.ThreeLayer.DataAccess.Provider.SQLParser
{
    internal abstract class OperatorParserFactory
    {
        private static readonly OperatorParserFactory _mssqlOperatorParserFactory = new MSSQLParserFactory();

        public abstract IOperatorParser GetParser(ConditionOperator op);

        protected OperatorParserFactory()
        {
        }

        public static OperatorParserFactory GetInstance(ProviderType provider)
        {
            switch (provider)
            {
                case ProviderType.SqlServer2005:
                    return _mssqlOperatorParserFactory;
                default:
                    throw new NotSupportedException("程序集未支持指定的数据库类型");
            }
            throw new NotSupportedException("程序集未支持指定的数据库类型");
        }
    }

    internal class MSSQLParserFactory : OperatorParserFactory
    {
        private IOperatorParser GetNormalParser(ConditionOperator op)
        {
            switch (op)
            {
                case ConditionOperator.Equal:
                    return new EqualParser();

                case ConditionOperator.NotEqual:
                    return new NotEqualParser();

                case ConditionOperator.LessThan:
                    return new LessThenParser();

                case ConditionOperator.LessEqual:
                    return new LessEqualParser();

                case ConditionOperator.MoreThan:
                    return new MoreThenParser();

                case ConditionOperator.MoreEqual:
                    return new MoreEqualParser();

                case ConditionOperator.NotIn:
                    return new NotInParser();

                case ConditionOperator.In:
                    return new InParser();

                case ConditionOperator.Between:
                    return new BetweenParser();

                case ConditionOperator.NotBetween:
                    return new NotBetweenParser();

                case ConditionOperator.Like:
                    return new LikeParser();

                case ConditionOperator.NotLike:
                    return new NotLikeParser();

                case ConditionOperator.IsNull:
                    return new IsNullParser();

                case ConditionOperator.IsNotNull:
                    return new IsNotNullParser();
            }
        }

        public override IOperatorParser GetParser(ConditionOperator op)
        {
            return GetNormalParser(op);
        }
    }

    internal class MySQLParserFactory : OperatorParserFactory
    {

    }
}
